//
//  SiJiCell.m
//  NtoccDriverNew
//
//  Created by 文 on 2019/12/20.
//  Copyright © 2019 GCY. All rights reserved.
//

#import "InviteDriverJoinCell.h"

@interface InviteDriverJoinCell ()
@property (weak, nonatomic) IBOutlet UIImageView *headImageView;
@property (weak, nonatomic) IBOutlet UILabel *chexingLabel;
@property (weak, nonatomic) IBOutlet UILabel *chepaiLabel;
@property (weak, nonatomic) IBOutlet UILabel *carInfoLabel;
@property (weak, nonatomic) IBOutlet UIView *line;
@property (weak, nonatomic) IBOutlet UILabel *nicknameLabel;
@property (nonatomic, strong) GQRatingView *ratingView;
@property (nonatomic, strong) UILabel *scoreLabel;
@property (weak, nonatomic) IBOutlet UIImageView *selectedImageView;

@end

@implementation InviteDriverJoinCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
    
    _nicknameLabel.textColor = Dark_TextColor;
    _chexingLabel.textColor = Light_TextColor;
    _chepaiLabel.textColor = Light_TextColor;
    _carInfoLabel.textColor = Light_TextColor;
    _line.backgroundColor = BackgroundColor;
    
    _scoreLabel = [[UILabel alloc] init];
    _scoreLabel.textColor = Light_TextColor;
    _scoreLabel.font = font(13);
    [self addSubview:_scoreLabel];
    
    //五角星 链式调用 [NSNumber numberWithInt:_model.avgBasicGrade]
    _ratingView = [GQRatingView init]
    .frameChain(CGPointMake(_headImageView.cy_right + 15, _nicknameLabel.cy_y + 3),15)
    .canTouchChain(NO)
    .needIntValueChain(NO)
    .scoreNumChain([NSNumber numberWithFloat:_model.avgBasicGrade])
    .normalColorChain([UIColor cy_colorWithHexString:@"#C0CDDE"])
    .highlightColorChian([UIColor cy_colorWithHexString:@"#FFC000"])
    .scroreBlockChain(^(NSNumber *scoreNumber){
    }).superViewChain(self);
}

- (void)buttonClick:(UIButton *)button {
    if (self.delegate && [self.delegate respondsToSelector:@selector(cellButtonIndexClick:withButton:)]) {
        [self.delegate cellButtonIndexClick:button.tag withButton:button];
    }
}

- (void)setModel:(SiJiListModel *)model {
    
    _model = model;
    
    if (model.isSelected == NO) {
        _selectedImageView.image = image(@"btn_siji_nomal");
    } else {
        _selectedImageView.image = image(@"btn_siji_selected");
    }
    
    setNetImage(_headImageView, _model.headImg, @"img_siji_dHead");
    _nicknameLabel.text = _model.name;
    _scoreLabel.text = CJStringWithFormat(@"%.1f",_model.avgBasicGrade);
    _chexingLabel.text = CJStringWithFormat(@"车型：%@",_model.vehicleClassificationName);
    _chepaiLabel.text = _model.vehicleLicenseNumber;
    _carInfoLabel.text = CJStringWithFormat(@"状态：%@ | 吨位：%@ | 车数：%ld辆",_model.vehicleLoadStatusName, _model.vehicleLoadWeightName, (long)_model.balance);
    
    CGSize size = [DCSpeedy dc_calculateTextSizeWithText:_model.name WithTextFont:14 WithMaxW:1000];
    
//    for(UIView *view in [self subviews])
//    {
//        if ([view isKindOfClass:[GQRatingView class]]) {
//            [view removeFromSuperview];
//        }
//    }
    _ratingView.cy_x = _headImageView.cy_right + 15 + size.width;
    _ratingView.scoreNum = [NSNumber numberWithFloat:_model.avgBasicGrade];
    
    _scoreLabel.frame = CGRectMake(_headImageView.cy_right + 15 + size.width + 80, _nicknameLabel.cy_y + 1, 60, 20);
    
    //操作按钮改变
    UIButton *bindBtn = [self viewWithTag:100];
    UIButton *dongBtn = [self viewWithTag:101];

    if ([CJStringWithFormat(@"%ld",(long)model.bindStatus) isEqual:@"1"]) {
        //未绑定
        [bindBtn setTitle:@"绑定车辆" forState:UIControlStateNormal];
    } else {
        [bindBtn setTitle:@"解绑车辆" forState:UIControlStateNormal];
    }
    
    //是否冻结（0-未冻结 1-已冻结）
    if ([CJStringWithFormat(@"%ld",(long)model.isFreeze) isEqual:@"0"]) {
        //未绑定
        [dongBtn setTitle:@"冻结" forState:UIControlStateNormal];
    } else {
        [dongBtn setTitle:@"解冻" forState:UIControlStateNormal];
    }
}


- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
